package com.lagou.dao.Impl;

import com.lagou.dao.CourseContentDao;
import com.lagou.domain.Course_Section;
import org.apache.commons.dbutils.QueryRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;

@Repository //相当于配置了bean标签
public class CourseContentDaoImpl implements CourseContentDao {

    @Autowired // 从IOC容器中获取到queryRunner对象
    private QueryRunner queryRunner;

    @Autowired
    private JdbcTemplate jdbcTemplate;


    @Override
    public int saveSection(Course_Section section) {
//        try {
//            // 编写SQL语句
//            String sql = "INSERT INTO course_section(\n" +
//                    "course_id,\n" +
//                    "section_name,\n" +
//                    "description,\n" +
//                    "order_num,\n" +
//                    "STATUS,\n" +
//                    "create_time,\n" +
//                    "update_time)VALUES(?,?,?,?,?,?,?);";
//
//            Object[] param = {section.getCourse_id(),section.getSection_name(),section.getDescription(),
//                    section.getOrder_num(),section.getStatus(),section.getCreate_time(),section.getUpdate_time()};
//
//            // 执行SQL语句
////            int row = queryRunner.update(sql, param);
//
//            return row;
//
//        } catch (SQLException e) {
//            e.printStackTrace();
//            return 0;
//        }
        // 编写SQL语句
        String sql = "INSERT INTO course_section(\n" +
                "course_id,\n" +
                "section_name,\n" +
                "description,\n" +
                "order_num,\n" +
                "STATUS,\n" +
                "create_time,\n" +
                "update_time)VALUES(?,?,?,?,?,?,?);";

        Object[] param = {section.getCourse_id(),section.getSection_name(),section.getDescription(),
                section.getOrder_num(),section.getStatus(),section.getCreate_time(),section.getUpdate_time()};

        // 执行SQL语句
        int row = jdbcTemplate.update(sql, param);

        return row;
    }
}
